package com.bootx.officialAccount.util;

import com.bootx.entity.Article;
import com.bootx.officialAccount.pojo.ArticlePojo;
import com.bootx.officialAccount.pojo.DraftAddResponse;
import com.bootx.util.JsonUtils;
import com.bootx.util.WebUtils;
import com.fasterxml.jackson.core.type.TypeReference;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author black
 */
public class DraftUtils {

    public static void draftSwitch(String accessToken) {
        String url="https://api.weixin.qq.com/cgi-bin/draft/switch?access_token="+accessToken+"&checkonly=CHECKONLY";
        Map<String,Object> params = new HashMap<>();
        String post = WebUtils.post(url, params);
        System.out.println(post);
    }
    public static void update(String accessToken, String mediaId, Integer integer, Article article) {
        String url="https://api.weixin.qq.com/cgi-bin/draft/update?access_token="+accessToken+"&checkonly=CHECKONLY";
        Map<String,Object> params = new HashMap<>();
        String post = WebUtils.post(url, params);
        System.out.println(post);
    }
    public static DraftAddResponse add(String accessToken, List<ArticlePojo> articles) {
        String url="https://api.weixin.qq.com/cgi-bin/draft/add?access_token="+accessToken;
        Map<String,Object> params = new HashMap<>();
        params.put("articles",articles);
        String post = WebUtils.postJson(url, JsonUtils.toJson(params),null);
        System.out.println(post);
        return JsonUtils.toObject(post, new TypeReference<DraftAddResponse>() {
        });
    }
}
